Skip to content

feat(config): new credentials model and profile deprecation#244

Open
LorrisSaintGenez wants to merge 8 commits into
mainfrom
feat/profile-depr
Open

feat(config): new credentials model and profile deprecation#244
LorrisSaintGenez wants to merge 8 commits into
mainfrom
feat/profile-depr

Conversation

@LorrisSaintGenez

@LorrisSaintGenez LorrisSaintGenez commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What

Migrates the CLI to a new credentials model (state.toml + OS keychain) and deprecates the legacy config.toml-based profile system.

state.toml store (#232): self-contained store for current application, per-app alias and api_key_uuid; atomic save (temp file + rename).

Per-app OS keychain (#233): SaveAppSecrets/LoadAppSecrets in pkg/keychain; neutral package to avoid import cycles with pkg/config.

API key UUID (#234): CreateAPIKey returns CreatedAPIKey{Value, UUID}; Application.APIKeyUUID populated by EnsureAPIKey.

Read resolution (#235): credential getters rewired — env → flag → state.toml + keychain → config.toml → admin fallback. Active app resolved once per command; keychain loaded once and cached.

Write paths (#236): auth login, application create and application select persist to the new model (keychain first, then state.toml); config.toml no longer written. Existing keys reused. auth crawler stores the crawler key in the per-app keychain entry.

Deprecations (#237): --profile flag and all profile subcommands marked deprecated with replacement hints; auth failure hint updated; all user-facing strings reworded from "CLI profile" to the new model.

Extra warning on legacy writes (26ae179): when state.toml already exists (new storage model in use), profile add/remove/setdefault print an additional warning that changes to config.toml profiles will be ignored in a future version.

Test

make build, then:

# Write + read new model
./algolia auth login
cat ~/.config/algolia/state.toml
security find-generic-password -s algolia-cli -a "app:<APP_ID>" -w | sed 's/^go-keyring-base64://' | base64 -d

# Re-select must not create a new dashboard key
./algolia application select

# Crawler key
./algolia auth crawler

# Legacy fallback — config.toml mtime must not change
./algolia indices list

# Deprecation warnings
./algolia --help
./algolia indices list -p <alias>
./algolia profile --help

# With a state.toml present, profile add/remove/setdefault print an extra
# warning: config.toml profile changes ignored in a future version
./algolia profile setdefault <name>

GROUT-305

LorrisSaintGenez and others added 6 commits June 9, 2026 08:15
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jun 11, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 139 complexity · 31 duplication

Metric Results
Complexity 139
Duplication 31

View in Codacy

TIP This summary will be updated as you push new changes.

@LorrisSaintGenez LorrisSaintGenez marked this pull request as ready for review June 11, 2026 20:48
profile add/remove/setdefault still write config.toml; once state.toml
exists (new storage model in use), changes to legacy profiles stop being
honored in a future version — say so before executing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@LorrisSaintGenez LorrisSaintGenez marked this pull request as draft June 11, 2026 21:48
@LorrisSaintGenez LorrisSaintGenez marked this pull request as ready for review June 15, 2026 16:09
…#248)

* feat(config): trigger the config.toml migration at startup (#245)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* chore(config): slim down the migration comments

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(config): harden the migration against bad config.toml files

Two startup-path regressions found while testing edge cases:

- An undecodable profile (root-level scalar, unconvertible field type)
  hit ConfiguredProfiles' log.Fatalf and bricked every command, --help
  included, forever (state.toml never written). The migration now
  decodes profiles itself and skips undecodable entries with a log.
- An unparseable config.toml was silently read as zero profiles, so an
  empty state.toml marked the migration as done forever. Migrate now
  aborts when config.toml cannot be parsed and retries on the next run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(config): migrate search_hosts and crawler_user_id to state.toml

The remaining non-secret profile data moves with the migration so it
survives the eventual config.toml removal. GetSearchHosts and
GetCrawlerUserID gain a new-model branch: the resolved application's
state.toml entry answers first, an empty value falls through to the
legacy config.toml lookup while both models coexist. admin_api_key
stays excluded as decided on the ticket.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* refactor(config): omit empty api_key_uuid from state.toml

Legacy migrated keys have no UUID, so without omitempty every migrated
entry serialized a noisy api_key_uuid = "". The field is only set by
new-model writes (app create/select); omitting the empty value matches
search_hosts/crawler_user_id and reads back identically.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(application): mark configured apps in select from state.toml

The select picker decorated choices from config.toml profiles only, so
apps configured under the new model showed as unconfigured. It now marks
an app "(configured)" when state.toml holds an entry for it, falling back
to legacy config.toml profiles while config.toml is still supported.

Adds Config.ApplicationInState for the state-only lookup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(application): state-aware "configured" marker + describe without auth

Two follow-ups from auditing the command tree against state.toml:

- application list marked apps configured from config.toml profiles only,
  so new-model apps showed as "(not configured)". It now uses the same
  state-first/config-fallback check as the select picker, centralized in
  apputil.ApplicationConfigured.
- describe walks the command tree and needs no credentials, but lacked
  skipAuthCheck so it failed on a machine with nothing configured. It now
  skips the auth check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(config): clearer error when the current app has no keychain key

When state.toml resolves a current application but its key isn't in this
machine's keychain (e.g. state.toml synced across machines without it),
GetAPIKey/GetCrawlerAPIKey returned the generic "not configured yet". The
error now names the application and points to the fix (`application
select` / `auth crawler`, or the matching env var). Re-authenticating
rewrites the keychain entry, so it restores a working state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* perf(config): short-circuit ShouldMigrate on the state.toml check

Check state.toml first: an already-migrated machine (the steady state,
hit on every command) now settles in a single stat instead of also
stat-ing config.toml. The boolean result is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* perf(application): O(1) configured-app lookup when listing/selecting

Marking apps "(configured)" called ConfiguredProfiles() (a full viper
re-parse) once per application — O(apps × profiles) with a heavy
constant. Now the config.toml profile app IDs are collected once into a
set (ProfileApplicationIDs); the per-app check is two O(1) map lookups
(cached state.toml + the set). Both `application list` and `application
select` build the set once before their loop.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant